package com.PlantVsZombies.Bullet;

import java.awt.Graphics;
import java.awt.Image;
import java.io.Serializable;

import com.PlantVsZombies.common.Life;
import com.PlantVsZombies.util.ImageUtil;

/**
 * 
 * 子弹爆炸类
 * 
 * @author Administrator
 *
 */
public class SunCollection extends Life implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	//爆炸坐标
	int x;
	int y;
	//是否存在
	boolean isLive ;
	//爆炸图片
	Image image;
	private double direct;
	
	public boolean getLive() {
		return isLive;
	}
	public void setLive(boolean isLive) {
		this.isLive = isLive;
	}
	public SunCollection(int x, int y,Image image){
		this.x = x;
		this.y = y;
		this.image = ImageUtil.sun.getImage();
		this.isLive = true;
		direct = Math.atan((double)(x)/(y+50));
	}
	
	//画爆炸
	public void drawMe(Graphics g){
		if(this.isLive)
			g.drawImage(image, x+50, y, null);
	}
	public void drawMe(Graphics g,int w,int h){
		if(this.isLive)
			g.drawImage(image, x+50, y,w,h, null);
	}
	@Override
	public int doRun() {
		if(x < 150 && y < 50){
			this.isLive = false;
			return 0;
		}
		move();
		try {
			Thread.sleep(100);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 1;
	}
	
	public void move() {
		x = (int) (x - 50*Math.sin(direct));
		y = (int) (y - 50*Math.cos(direct));
	}
}
